/**
 * 添加或修改商品活动信息
 * @param {} id
 * @param {} title
 * @param {} goodsId
 * @param {} goodsCode
 * @return {}
 */
function addOrUpdGoodsActivityWin(id, title) {
	var addOrUpdGoodsActivityForm = new Ext.form.FormPanel({
		id : 'addOrUpdGoodsActivityForm',
		frame : true,
		buttonAlign : 'center',
		monitorValid : true,
		bodyBorder : false,
		fileUpload : true,// 上传文件设置为true
		reader : new Ext.data.JsonReader({
					success : 'success',
					root : 'data'
				}, [{
							name : "id"
						}, {
							name : "ruleGroupId"
						}, {
							name : "activityName"
						}, {
							name : "activityBeginDate"
						}, {
							name : "activityEndDate"
						}, {
							name : "enjoyOtherActivtity"
						}, {
							name : "isEnable"
						}, {
							name : "createdDate"
						}, {
							name : "createdName"
						}, {
							name : "updatedDate"
						}, {
							name : "updatedName"
						}, {
							name : "ruleGroupName"
						}]),
		items : [{
			layout : 'column',
			border : false,
			items : [{
				labelWidth : 110,
				columnWidth : .48,
				layout : 'form',
				border : false,
				items : [{
							xtype : 'hidden',
							name : 'id',
							value : id
						}, {
							xtype : 'textfield',
							anchor : '100%',
							labelStyle : "text-align:right;",
							fieldLabel : "<span style='color:#F00'>*</span>活动名称",
							allowBlank : false,
							blankText : '活动名称不能为空',
							defaultFirstRow : 1,
							name : "activityName"
						}]
			}, {
				labelWidth : 110,
				columnWidth : .48,
				layout : 'form',
				border : false,
				items : [{
							id : 'goodsActivityForm_ruleGroupId',
							anchor : '100%',
							labelStyle : "text-align:right;",
							fieldLabel : "<span style='color:#F00'>*</span>规则名称",
							hiddenName : 'ruleGroupId',
							xtype : 'ruleGroupCmb',
							allowBlank : false,
							showValue : true,
							existall : false
						}]
			}]
		}, {
			layout : 'column',
			border : false,
			items : [{
				labelWidth : 110,
				columnWidth : .48,
				layout : 'form',
				border : false,
				items : [{
					anchor : '100%',
					id : "goodsActivityForm_beginDate",
					xtype : "datetimefield",
					name : "activityBeginDate",
					labelStyle : "text-align:right;",
					fieldLabel : "<span style='color:#F00'>*</span>活动开始时间",
					allowBlank : false,
					editable : false,
					emptyText : "活动开始时间不能为空",
					format : 'Y-m-d H:i:s',
					listeners : {
						'select' : function() {
							Ext.getCmp('goodsActivityForm_EndDate')
									.setMinValue(this.getValue());
						}
					}

				}]
			}, {
				labelWidth : 110,
				columnWidth : .48,
				layout : 'form',
				border : false,
				items : [{
					anchor : '100%',
					id : "goodsActivityForm_EndDate",
					xtype : "datetimefield",
					name : "activityEndDate",
					labelStyle : "text-align:right;",
					fieldLabel : "<span style='color:#F00'>*</span>活动结束时间",
					allowBlank : false,
					editable : false,
					emptyText : "活动结束时间不能为空",
					format : 'Y-m-d H:i:s',
					listeners : {
						'select' : function() {
							Ext.getCmp('goodsActivityForm_beginDate')
									.setMaxValue(this.getValue());
						}
					}
				}]
			}]
		}, {
			layout : 'column',
			border : false,
			items : [{
				labelWidth : 110,
				columnWidth : .48,
				layout : 'form',
				border : false,
				items : [{
							xtype : 'localcommonbox',
							anchor : '100%',
							labelStyle : "text-align:right;",
							fieldLabel : "<span style='color:#F00'>*</span>是否参与其他活动",
							hiddenName : "enjoyOtherActivtity",
							loaclarr : [['0', '不参与'], ['1', '参与']],
							allowBlank : false,
							value : 0
						}]
			}, {
				layout : 'form',
				border : false,
				labelWidth : 110,
				columnWidth : .48,
				items : [{
							xtype : 'localcommonbox',
							anchor : '100%',
							labelStyle : "text-align:right;",
							fieldLabel : "<span style='color:#F00'>*</span>是否可用",
							hiddenName : "isEnable",
							allowBlank : false,
							loaclarr : [['0', '可用'], ['1', '不可用']],
							value : 0
						}]
			}]
		}],
		buttons : [{
					text : '确定',
					formBind : true,
					handler : function() {
						addOrUpdGoodsActivity();
					}
				}, {
					text : "取消",
					handler : function() {
						addOrUpdGoodsActivityWindow.close();
					}
				}]
	});
	var addOrUpdGoodsActivityWindow = new Ext.Window({
				id : 'addOrUpdGoodsActivityWindow',
				closeAction : 'close',
				title : title,
				closable : true,
				plain : true,
				modal : true,
				width : 640,
				height : 180,
				draggable : false, // 不可拖动
				resizable : false, // 不可调整
				buttonAlign : 'center',
				autoDestroy : true,
				layout : 'fit',
				items : [addOrUpdGoodsActivityForm],
				listeners : {
					'show' : function() {
						selectGoodsActivityUpdById(id);
					},
					'beforeshow' : function() {
						addOrUpdGoodsActivityWindow.center();
					}
				}
			});
	return addOrUpdGoodsActivityWindow;

};

/**
 * 查询商品活动对象
 * 
 * @param {}
 *            id
 */
function selectGoodsActivityUpdById(id) {
	if (id != null && id != "undefined") {
		Ext.getCmp("addOrUpdGoodsActivityForm").getForm().load({
			// deferredRender : false,
			url : __ctxPath + "/goodsManager/selectGoodsActivityUpdById",
			params : {
				id : id
			},
			method : "POST",
			waitTitle : "请稍候",
			waitMsg : "正在载入数据...",
			root : "data",
			success : function(form, action) {
				var data = action.result.data;

				// 设置规则组名称
				Ext.getCmp('goodsActivityForm_ruleGroupId')
						.setValue(data.ruleGroupId);
				Ext.getCmp('goodsActivityForm_ruleGroupId')
						.setRawValue(data.ruleGroupName);
			},
			failure : function(f, g) {
				Ext.MessageBox.show({
							title : "操作信息",
							msg : "数据加载失败!",
							buttons : Ext.MessageBox.OK,
							icon : Ext.MessageBox.ERROR
						});
			}
		});
	}
}
/**
 * 添加或修改商品活动信息
 */
function addOrUpdGoodsActivity() {
	var addOrUpdGoodsActivityForm = Ext.getCmp("addOrUpdGoodsActivityForm");
	if (addOrUpdGoodsActivityForm.getForm().isValid()) {
		Ext.Msg.confirm("提示框", "确认要保存商品活动信息吗?", function(button) {
					if (button == "yes") {
						addOrUpdGoodsActivityForm.getForm().submit({
							url : __ctxPath
									+ '/goodsManager/addOrUpdGoodsActivity',
							waitTitle : "请稍候",
							waitMsg : "正在提交表单，请稍候......",
							failure : function(response, options) {
								var jsonData = Ext.util.JSON
										.decode(options.response.responseText);
								Ext.MessageBox.show({
											title : "错误提示",
											msg : jsonData.data,
											buttons : Ext.MessageBox.OK,
											icon : Ext.MessageBox.ERROR
										});
							},
							success : function(response, options) {
								var jsonData = Ext.util.JSON
										.decode(options.response.responseText);
								Ext.MessageBox.show({
											title : "信息提示",
											msg : jsonData.data,
											buttons : Ext.MessageBox.OK,
											icon : Ext.MessageBox.INFO
										});
								Ext.getCmp("addOrUpdGoodsActivityWindow")
										.close();
								var gridPanel = Ext
										.getCmp('goodsActivityManagerGrid');
								if (typeof(gridPanel) != 'undefined') {
									gridPanel.store.reload();
								}
							}
						});
					}
				});
	}
}